﻿using System;
using System.Globalization;
using System.Threading;

namespace élénkPróbája.Test
{
    public class CultureScope : IDisposable
    {
        CultureInfo _originalUiCulture;
        CultureInfo _originalCulture;

        public CultureScope(CultureInfo culture)
        {
#if !CoreCLR
            _originalCulture = Thread.CurrentThread.CurrentCulture;
            _originalUiCulture = Thread.CurrentThread.CurrentUICulture;

            Thread.CurrentThread.CurrentCulture = culture;
            Thread.CurrentThread.CurrentUICulture = culture;
#else
			_originalCulture = CultureInfo.CurrentCulture;
			_originalUiCulture = CultureInfo.CurrentUICulture;

			CultureInfo.CurrentCulture = culture;
			CultureInfo.CurrentUICulture = culture;
#endif
        }

        public CultureScope(string culture) : this(new CultureInfo(culture))
        {

        }

        public void Dispose()
        {
#if !CoreCLR
            Thread.CurrentThread.CurrentCulture = _originalCulture;
            Thread.CurrentThread.CurrentUICulture = _originalUiCulture;
#else
			CultureInfo.CurrentCulture = _originalCulture;
			CultureInfo.CurrentUICulture = _originalUiCulture;
#endif
        }

        public static void SetDefaultCulture()
        {
#if !CoreCLR
            Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
#else
			CultureInfo.CurrentCulture = new CultureInfo("en-US");
			CultureInfo.CurrentUICulture = new CultureInfo("en-US");
#endif
        }
    }
}